/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clientes;

import alertas.alertError;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author rocio
 */
@Entity
@Table(name = "doctor", catalog = "lpd", schema = "")
@NamedQueries({@NamedQuery(name = "Doctor.findAll", query = "SELECT d FROM Doctor d"), @NamedQuery(name = "Doctor.findByIDdoctor", query = "SELECT d FROM Doctor d WHERE d.iDdoctor = :iDdoctor"), @NamedQuery(name = "Doctor.findByNombre", query = "SELECT d FROM Doctor d WHERE d.nombre = :nombre"), @NamedQuery(name = "Doctor.findByNumcolegiado", query = "SELECT d FROM Doctor d WHERE d.numcolegiado = :numcolegiado"), @NamedQuery(name = "Doctor.findByIDcliente", query = "SELECT d FROM Doctor d WHERE d.iDcliente = :iDcliente")})
public class Doctor implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_doctor")
    private Integer iDdoctor;
    @Basic(optional = false)
    @Column(name = "Nombre")
    private String nombre;
    @Column(name = "Num_colegiado")
    private Integer numcolegiado;
    @Basic(optional = false)
    @Column(name = "ID_cliente")
    private int iDcliente;

    public Doctor() {
    }

    public Doctor(Integer iDdoctor) {
        this.iDdoctor = iDdoctor;
        this.nombre="";
        this.iDcliente=1;
    }

    public Doctor(Integer iDdoctor, String nombre, int iDcliente) {
        this.iDdoctor = iDdoctor;
        this.nombre = nombre;
        this.iDcliente = iDcliente;
    }


    public Doctor(String IDdoctor, String Nombre, String IDcliente) {

        Integer a=Integer.parseInt(IDdoctor);
        this.setIDdoctor(a);
        if(Nombre==null || Nombre.equals("")){
            alertError error=new alertError("el nombre es un campo obligatorio");
           error.setVisible(true);
        }else {
            this.nombre=Nombre;
        }
        if(IDcliente==null || IDcliente.equals("")){
            alertError error=new alertError("el cliente es un campo obligatorio");
           error.setVisible(true);
        }else{
            Integer b=Integer.parseInt(IDcliente);
            this.iDcliente=b;
        }

    }

    public Doctor(String IDdoctor, String Nombre, String Numero, String IDcliente) {
        this.iDdoctor=Integer.parseInt(IDdoctor);
        if(Nombre==null || Nombre.equals("")){
           alertError error=new alertError("el nombre es un campo obligatorio");
           error.setVisible(true);
        }else{this.nombre = Nombre;}
        if(Numero==null || Numero.equals("")){
            this.numcolegiado=null;
        }else{this.numcolegiado = Integer.parseInt(Numero);}
        if(IDcliente==null || IDcliente.equals("")){
            alertError error=new alertError("el id del cliente es un campo obligatorio");
           error.setVisible(true);
        }else{this.iDcliente = Integer.parseInt(IDcliente);}


    }

    public Integer getIDdoctor() {
        return iDdoctor;
    }

    public void setIDdoctor(Integer iDdoctor) {
        Integer oldIDdoctor = this.iDdoctor;
        this.iDdoctor = iDdoctor;
        changeSupport.firePropertyChange("IDdoctor", oldIDdoctor, iDdoctor);
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        String oldNombre = this.nombre;
        this.nombre = nombre;
        changeSupport.firePropertyChange("nombre", oldNombre, nombre);
    }

    public Integer getNumcolegiado() {
        return numcolegiado;
    }

    public void setNumcolegiado(Integer numcolegiado) {
        Integer oldNumcolegiado = this.numcolegiado;
        this.numcolegiado = numcolegiado;
        changeSupport.firePropertyChange("numcolegiado", oldNumcolegiado, numcolegiado);
    }

    public int getIDcliente() {
        return iDcliente;
    }

    public void setIDcliente(int iDcliente) {
        int oldIDcliente = this.iDcliente;
        this.iDcliente = iDcliente;
        changeSupport.firePropertyChange("IDcliente", oldIDcliente, iDcliente);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (iDdoctor != null ? iDdoctor.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
       if (!(object instanceof Doctor)) {
            return false;
        }
        Doctor other = (Doctor) object;
        if ((this.iDdoctor == null && other.iDdoctor != null) || (this.iDdoctor != null && !this.iDdoctor.equals(other.iDdoctor))) {
            return false;
        }
        return true;
    }

   

    @Override
    public String toString() {
        return "laboratorio.Doctor[iDdoctor=" + iDdoctor + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
